<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "order".
 *
 * @property int $id
 * @property string $order_sn 订单号
 * @property int $price
 * @property int $buy_user_id 购买人
 * @property int $sellers_user_id 出售方
 * @property int $product_id
 * @property int $status 1=待付款   2 =确认中   3=已确认
 * @property string|null $ctime
 * @property string|null $utime
 * @property int|null $users_product_id
 */
class Orders extends \yii\db\ActiveRecord {
    /**
     * {@inheritdoc}
     */
    public static function tableName() {
        return 'orders';
    }

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['buy_user_id', 'sellers_user_id', 'product_id', 'status', 'users_product_id'], 'integer'],
            [['ctime', 'utime'], 'safe'],
            [['order_sn'], 'string', 'max' => 80],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'order_sn' => 'Order Sn',
            'price' => 'Price',
            'buy_user_id' => 'Buy User ID',
            'sellers_user_id' => 'Sellers User ID',
            'product_id' => 'Product ID',
            'status' => 'Status',
            'ctime' => 'Ctime',
            'utime' => 'Utime',
            'users_product_id' => 'Users Product ID',
        ];
    }

    public function getProduct() {
        return $this->hasOne(Product::class, ['id' => 'product_id']);
    }

    public function getUsersProduct() {
        return $this->hasOne(UsersProduct::class, ['id' => 'users_product_id']);
    }

    public function getBuyUser() {
        return $this->hasOne(Users::class, ['id' => 'buy_user_id']);
    }

    public function getSellersUser(){
        return $this->hasOne(Users::class, ['id' => 'sellers_user_id']);
    }

}
